'''
Author: xialang333@gmail.com
Date: 2024-07-26 11:20:04
LastEditTime: 2024-08-02 17:24:42
'''
from django.db import models
from utils.models import CoreModel, BaseModel, table_prefix, CoreIntModel


class FilesModel(BaseModel):
    name = models.CharField(max_length=64, verbose_name="文件名", help_text="文件名")
    file = models.FileField(upload_to='media/uploads/')

    class Meta:
        db_table = table_prefix + "files_storage"
        verbose_name = '文件存储表'
        verbose_name_plural = verbose_name
        ordering = ('create_datetime',)


class ApplicationModel(CoreIntModel):
    name = models.CharField(max_length=64, verbose_name="应用名称", help_text="应用名称")
    ver = models.CharField(max_length=64, verbose_name="应用版本", help_text="应用版本")
    deployment = models.TextField(verbose_name="部署脚本", help_text="部署脚本")
    
    class Meta:
        db_table = table_prefix + "application"
        verbose_name = '应用部署'
        verbose_name_plural = verbose_name
        ordering = ('create_datetime',)


class ApplicationDepLogs(BaseModel):
    appserver = models.ForeignKey(ApplicationModel, on_delete=models.CASCADE)
    ipaddr = models.CharField(max_length=64, verbose_name="部署地址", help_text="部署地址")
    status =  models.IntegerField(default=1, verbose_name="任务状态", help_text="任务状态")
    logs = models.TextField(verbose_name="部署日志", help_text="部署日志")

    class Meta:
        db_table = table_prefix + "application_dep_log"
        verbose_name = '应用部署记录'
        verbose_name_plural = verbose_name
        ordering = ('-create_datetime',)